//Queue Implementation

#include "queue.h"
#include "Customer_Obj.h"
#include "Time.h"
#include <iostream>
using namespace std;

queue::queue(){
               maxSize = 0;
               numUsed = 0;
               maxWait = 0;
               queue_data = new Customer_Obj[800];
}

bool queue::enqueue(Customer_Obj customer){
     if(isFull())
                 return(false);
     queue_data[numUsed] = customer;
     numUsed++;
     if(numUsed > maxSize)
                maxSize = numUsed;
     return(true);
}

Customer_Obj queue::dequeue(){
             Customer_Obj customer = queue_data[0];
             waitTimeAvg[numUsed] = waitTime[0];
             
             if(waitTime[0] > maxWait)
                                              maxWait = waitTime[0];
             
             for(int i = 0; i < numUsed; i++){
                     queue_data[i] = queue_data[i+1];
                     waitTime[i] = waitTime[i+1];
             }
             
             numUsed--;
             for(int i = 0; i < numUsed; i++){
                   waitTime[i] += customer.getLineProcessTime();
             }
             
             queue_data[0].setActionTime(queue_data[0].getLineProcessTime());
             
             
             return(customer);
}
             
bool queue::isEmpty(){
     if(numUsed == 0)
                return(true);
     else
         return(false);
}

bool queue::isFull(){
     if(numUsed == 800)
                return(true);
     else
         return(false);
}

int queue::getCurrentSize(){
    return(numUsed);
}

int queue::getMaxSize(){
    return(maxSize+1);
}

int queue::getMaxWait(){
    return(maxWait);
}

int queue::getAvgWait(){
    int temp = 0;
    for(int i = 0; i < numProcessed; i++){
            temp += waitTimeAvg[i];
    }
    avgWait = temp / numProcessed;
    return(avgWait);
}

int queue::getNumProcessed(){
    return(numProcessed);
}

Customer_Obj queue::peek(){
             //cout << "Peek Started." << endl;
             //cout << queue_data[0].getActionTime() << endl;
             //cout << (*sync_obj).return_time() << endl;
             //cout << queue_data[0].getFirstName() << endl;
             //if(queue_data[0].getActionTime() <= (*sync_obj).return_time() && queue_data[0].getFirstName() != "" && queue_data[0].getActionTime() > 0)
                                              //queue_data[0].setActionTime(queue_data[0].getLineProcessTime() + (*sync_obj).return_time());
             //cout << "Ready to return." << endl;
             return(queue_data[0]);
}

void queue::set_sync(sync *sync_object){
     sync_obj = sync_object;
     //cout << "Sync Set: " << (*sync_obj).return_time() << endl;
}
